package cn.itsource.pethome.base.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: hong
 * @Description:
 * @Date:
 * @Modified: By:
 */
@Configuration
public class CustomParamResolverConfigurer implements WebMvcConfigurer {


    @Autowired
    private LoginCheckInterceptor loginCheckInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //将自定义的拦截器，添加到Springmvc的配置中，这样就可以生效
        registry.addInterceptor(loginCheckInterceptor).addPathPatterns("/**")
                .excludePathPatterns(
                        "/user/login","/file/upload","/shop/register",
                        "/user/sendmobilecode/**","/user/checkphone/**","/user","/empl/login"
                );

    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>> ();
        converters.add(new MappingJackson2HttpMessageConverter());
        resolvers.add(new CustomMethodArgumentResolver ());
        //resolvers.add (new MyRequestResponseBodyMethodProcessor (converters));
        WebMvcConfigurer.super.addArgumentResolvers(resolvers);

    }
//    @Bean
//    public RequestMappingHandlerAdapter requestMappingHandlerAdapter() {
//        RequestMappingHandlerAdapter requestMappingHandlerAdapter = super.requestMappingHandlerAdapter();
//        List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
//        converters.add(new DataMessageConvert());
//        List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<HandlerMethodArgumentResolver> ();
//        argumentResolvers.add(new MyResolver(converters));
//        requestMappingHandlerAdapter.setCustomArgumentResolvers(argumentResolvers);
//        List<HandlerMethodReturnValueHandler> returnValueHandlers = new ArrayList<HandlerMethodReturnValueHandler>();
//        returnValueHandlers.add(new MyResolver(converters));
//        requestMappingHandlerAdapter.setCustomReturnValueHandlers(returnValueHandlers);
//        return requestMappingHandlerAdapter;
//    }
}


